@extends('frontend/layouts/bootstrap')

@section('content')
<style>
form .table { margin-bottom: 5px;}
form .table th, form .table td {padding: 4px 8px;}
</style>

<h2>Машины жагсаалт</h2>

{{-- FILTER --}}
<form class="form-inline" style="margin: 0;" action="{{ route('car_balance.main.car_list_filter') }}" method="post">
    <table class="table table-bordered">
        <thead style="background-color: #f0f0f0;">
        <tr>
            <th>車体番号</th>
            <th>日付</th>
            <th>Customer</th>
            <th>オークション</th>
            <th>サービス会社</th>
            <th>車種</th>
            <th>CONTAINER ID</th>
            <th>PRICE</th>
            <th>Action</th>
        </tr>
        </thead>

        <tbody>
        <tr>
            <td>
                <input placeholder="車体番号" type="text" name="chassis_no" class="input-small" value="{{ $filters['chassis_no'] ? $filters['chassis_no'] : '' }}"/><br/>
@if (empty($customer)) <input placeholder="comment" type="text" name="comment" class="input-small" value="{{ $filters['comment'] ? $filters['comment'] : '' }}"/> @endif
            </td>
            <td>
                <input class="input-small" placeholder="日付" type="text" name="purchase_date" id="daterange" value="{{ count($filters['purchase_date']) > 1 ? $filters['purchase_date'][0] .' - '.$filters['purchase_date'][1] : '' }}"/>
            </td>
            <td>
                @if (empty($customer))
                {{ Form::select('customer_id', $customer_list, $filters['customer_id'], array('class' => 'input-small')) }}
                @else
                {{ $customer->customer_id }}
                @endif
            </td>
            <td>
                {{ Form::select('car_auction_id', $car_auction_list, $filters['car_auction_id'], array('class' => 'input-small')) }}
            </td>
            <td>
                {{ Form::select('service_company_id', $service_company_list, $filters['service_company_id'], array('class' => 'input-medium')) }}
            </td>
            <td style="width: 70px;">
                {{-- Form::select('car_makers', $car_makers, '', array('data-placeholder' => 'Car maker', 'class' => 'input-medium', 'name' => 'makers[]')) --}}
                {{-- Form::select('car_maker', $car_makers, $filters['makers'], array('class' => 'input-small')) --}}
                {{ Form::select('car_maker', $car_makers, $filters['car_maker'], array('class'=>'input-medium', 'id' => 'car_maker')) }}
                <span id="car_name"></span>
            </td>
            <td>
                <input placeholder="Container ID" type="text" name="container_id" class="input-small" value="{{ $filters['container_id'] ? $filters['container_id'] : '' }}"/>
                </br><input id="container_id_cb" placeholder="未設定" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" name="container_id_cb" {{ $filters['container_id_cb'] ? 'checked' : '' }}/><label for="container_id_cb">未設定</label>
                <input placeholder="Container NO" type="text" name="container_no" class="input-small" value="{{ $filters['container_no'] ? $filters['container_no'] : '' }}"/>
                </br><input id="container_no_cb" placeholder="未設定" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" name="container_no_cb" {{ $filters['container_no_cb'] ? 'checked' : '' }}/><label for="container_no_cb">未設定</label>
            </td>
            <td>
                <input placeholder="Price from" type="text" class="input-small" name="price_from" value="{{ $filters['price_from'] ? $filters['price_from'] : '' }}"/>
                <input placeholder="Price to" type="text" class="input-small" name="price_to" value="{{ $filters['price_to'] ? $filters['price_to'] : '' }}"/>
            </td>
            <td style="width: 80px;">
                {{ Form::token() }}
                <button type="submit" class="btn">Apply Filter</button>
                <a href="{{ route('car_balance.main.car_list') }}?reset=1" >Reset</a>
            </td>
        </tr>
        </tbody>
    </table>
</form>

@if ($cars->count())
<div>{{ $cars->getTotal() }} results.</div>
@include('nimo/domains/car_balance/page')
<div class="container-wrapper">
    <div class="fixed-th-table-wrapper">
        <table class="table table-bordered table-condensed table-hover">
            <thead style="background-color: #f0f0f0; white-space:nowrap;">
            <tr>
                <th title="Action">Action</th>
                <th title="Date">日付</th>
                <th title="Auction">オーク会場</th>
                <th title="Auction no">Lot no</th>
                <th title="Car name">車種</th>
                <th title="Car year">年式</th>
                <th title="Car year month">年月</th>
                <th title="Chassis number">車体番号</th>
            </tr>
            </thead>
            <tbody style="font-size: 11px;">
            @foreach($cars as $car)
            <tr>
                <div style="position: absolute; z-index: 1;">
                <th>
                    <a class="btn btn-primary btn-mini" href="{{ route('car_balance.car.car_show', $car->id) }}" title="Detial"><i class="icon-zoom-in icon-white"></i></a>
                    <a class="btn btn-primary btn-mini" href="{{ route('car_balance.car.expense', $car->id) }}" title="Expenses"><i class="icon-dollar icon-white"></i></a>
                </th>
                <th>{{ $car->purchase_date }}</th>
                <th>{{ $car->auction_name }}</th>
                <th>{{ $car->lot_no }}</th>
                <th>{{ $car->car_maker }} {{ $car->car_name }}</th>
                <th>{{ $car->car_year }}</th>
                <th>{{ $car->car_year_month }}</th>
                <th>{{ $car->chasis_no }}</th>
                </div>
            </tr>
            @endforeach
            </tbody>
        </table>
    </div>
    <div class="scrolled-td-table-wrapper">
        <table class="table table-bordered table-condensed table-hover">
            <thead style="background-color: #f0f0f0; white-space:nowrap;">
            <tr>
                <th title="Action">Action</th>
                <th title="Date">日付</th>
                <th title="Auction">オーク会場</th>
                <th title="Auction no">Lot no</th>
                <th title="Car name">車種</th>
                <th title="Car year">年式</th>
                <th title="Car year month">年月</th>
                <th title="Chassis number">車体番号</th>
                <td title="Customer">Customer</td>
                <td title="Auction sheet">出品表</td>
                <td title="Service company">会社</td>
                <td title="Container NO">Container</td>
                <td title="Total Price">合計</td>
                <td title="Price">購入額</td>
                <td title="Consumption tax">消費税</td>
                <td title="Auction commission">落札料</td>
                <td title="Recycle fee">Recycle</td>
                <td title="Car tax amount">自動車税</td>
                <td title="Tic send fee">送料</td>
                <td title="Transport fee">陸送</td>
                <td title="Others">その他</td>
                <td title="Container ID">Container ID</td>
                <td title="Vanning company">バンニング会社</td>
            </tr>
            </thead>
            <tbody style="font-size: 11px;">
            @foreach($cars as $index => $car)
            <tr>
                <th>
                    @if ($index == 0 && count($cars) == 1 )
                        <?php $prev=0; ?>
                        <?php $next=0; ?>
                    @elseif ($index == 0)
                        <?php $prev=0; ?>
                        <?php $next=$cars[$index+1]->id; ?>
                    @elseif ($index+1 == count($cars))
                        <?php $next=0; ?>
                        <?php $prev=$cars[$index-1]->id; ?>
                    @else
                        <?php $prev=$cars[$index-1]->id; ?>
                        <?php $next=$cars[$index+1]->id; ?>
                    @endif
                    {{ Session::put('prevCarId'.$car->id, $prev); }}
                    {{ Session::put('nextCarId'.$car->id, $next); }}
                    <a class="btn btn-primary btn-mini" href="{{ route('car_balance.car.car_show', $car->id) }}" title="Detial"><i class="icon-zoom-in icon-white"></i></a>
                    <a class="btn btn-primary btn-mini" href="{{ route('car_balance.car.expense', $car->id) }}" title="Expenses"><i class="icon-dollar icon-white"></i></a>
                </th>
                <th>{{ $car->purchase_date }}</th>
                <th>{{ $car->auction_name }}</th>
                <th>{{ $car->lot_no }}</th>
                <th>{{ $car->car_maker }} {{ $car->car_name }}</th>
                <th>{{ $car->car_year }}</th>
                <th>{{ $car->car_year_month }}</th>
                <th>{{ $car->chasis_no }}</th>
                <td>{{ $car->customer ? link_to_route('car_balance.customer.show', $car->customer->name, $car->customer->id, array()) : 'NULL' }}</td>
                <td>
                    @if ( $car->auction_sheet_upload_flag )
                    <a target="_blank" style="margin-left: 15px;" class="btn btn-success btn-mini" href="{{route('car_balance.main.display', array('type'=>'auction', 'file'=>'auction_sheet_'.$car->chasis_no.'.pdf'))}}" title="{{ $car->car_year }}-{{ $car->car_name }}-{{ $car->chasis_no; }}"><i class="icon-zoom-in icon-white"></i></a>
                    @else
                    No pdf.
                    @endif
                </td>
                <td>{{ link_to_route('car_balance.service_company.show', $car->service_company_id == '1' ? 'TIC' : 'NMC', $car->service_company_id, array()) }}</td>
                <td> @if ($car->container_id) <a href="{{ route('car_balance.container.confirmed', array('container_id'=>$car->container_id, 'reset'=>1)) }}"  target="_blank">  {{ $car->container_no }} </a> @else {{ $car->container_no }} @endif </td>
                <td style="text-align: right;">{{ $car->payment_total_amount ? number_format($car->payment_total_amount, 0) : 0; }}</td>
                <td style="text-align: right;">{{ $car->purchase_price ? number_format($car->purchase_price, 0) : 0; }}</td>
                <td style="text-align: right;">{{ number_format(($car->purchase_price*$car->vat_percent)/100, 0); }}</td>
                <td style="text-align: right;">{{ $car->auction_commission ? number_format($car->auction_commission, 0) : 0; }}</td>
                <td style="text-align: right;">{{ $car->recycle_amount ? number_format($car->recycle_amount, 0) : 0; }}</td>
                <td style="text-align: right;">{{ $car->car_tax_amount ? number_format($car->car_tax_amount, 0) : 0; }}</td>
                <td style="text-align: right;">{{ $car->tic_send_fee ? number_format($car->tic_send_fee, 0) : 0; }}</td>
                <td style="text-align: right;">{{ $car->transfer_fee ? number_format($car->transfer_fee, 0) : 0; }}</td>
                <td style="text-align: right;">{{ $car->others ? number_format($car->others, 0) : 0; }}</td>
                <td> @if ($car->container_id) <a href="{{ route('car_balance.container.confirmed', array('container_id'=>$car->container_id, 'reset'=>1)) }}"  target="_blank">  {{ $car->container_id }} </a> @else {{ $car->container_id }} @endif </td>
                <td>{{ $car->container_port ? link_to_route('car_balance.vanning_company_branch.show', $car->container_port, $car->container_port, array()) : 'NULL' }}</td>
            </tr>
            @endforeach
            </tbody>
        </table>
    </div>

@include('nimo/domains/car_balance/page')

@else
    Хайлтад тохирох үр дүн алга
@endif

@stop


@section('pagestyles')
<link rel="stylesheet" type="text/css" href={{ asset('assets/chosen-bootstrap/chosen.min.css') }} />
<link rel="stylesheet" type="text/css" href={{ asset('assets/bootstrap-daterangepicker/daterangepicker.css') }} />
<link rel="stylesheet" type="text/css" href={{ asset('assets/lightbox/lightbox.css') }} />
<style type="text/css" media="screen">
    .container-wrapper {
        /* Attach fixed-th-table to this container,
           in order to layout fixed-th-table
           in the same way as scolled-td-table" */
        position: relative;

        /* Truncate fixed-th-table */
        overflow: hidden;
        width: 1170px;
        white-space: nowrap;
    }
    table thead td {
        font-weight: bold;
    }
    table tbody th {
        font-weight: normal !important;
    }

    .fixed-th-table-wrapper td,
    .fixed-th-table-wrapper th,
    .scrolled-td-table-wrapper td,
    .scrolled-td-table-wrapper th {
        /* Set background to non-transparent color
           because two tables are one above another.
         */
        background: white;
    }
    .fixed-th-table-wrapper {
        /* Make table out of flow */
        position: absolute;
    }
    .fixed-th-table-wrapper th {
        /* Place fixed-th-table th-cells above
           scrolled-td-table td-cells.
         */
        position: relative;
        z-index: 1;
    }
    .scrolled-td-table-wrapper td {
        /* Place scrolled-td-table td-cells
           above fixed-th-table.
         */
        position: relative;
    }
    .scrolled-td-table-wrapper {
        /* Make horizonal scrollbar if needed */
        overflow-x: scroll;
    }

</style>
@stop

@section('pagescripts')
<!--page specific plugin scripts-->
<script type="text/javascript" src={{ asset('assets/chosen-bootstrap/chosen.jquery.min.js') }}></script>
<script type="text/javascript" src={{ asset('assets/bootstrap-daterangepicker/date.js') }} ></script>
<script type="text/javascript" src={{ asset('assets/bootstrap-daterangepicker/daterangepicker.js') }}></script>
<script type="text/javascript" src={{ asset('assets/lightbox/lightbox-2.6.min.js') }}></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[name="purchase_date"]').daterangepicker({format:"yyyy-MM-dd"});
    });
    if ($('#car_maker').val().length){
        $.ajax({
            url: "{{ route('car_balance.car.getCarName') }}?maker='+$('#car_maker').val()+'&filter=1'",
            type: "get",
            data: {maker : $('#car_maker').val(), filter: 1},
            success: function(data){
                $('#car_name').html(data);
            }});
    }
    $('select[name=car_maker]').on('change', function(e){
        $.get('{{ route('car_balance.car.getCarName') }}?maker='+this.value+'&filter=1', function(d){
            $('#car_name').html(d);
        })
        console.log(this.value);
    });

</script>
@stop